package com.web.main.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @create 2020-11-19 21:14
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("adminCreateTime", new Date(), metaObject);
        this.setFieldValByName("adminModifyTime", new Date(), metaObject);

        this.setFieldValByName("supplierCreateTime", new Date(), metaObject);
        this.setFieldValByName("supplierModifyTime", new Date(), metaObject);

        this.setFieldValByName("pileCreateTime", new Date(), metaObject);
        this.setFieldValByName("pileModifyTime", new Date(), metaObject);
        this.setFieldValByName("siteCreateTime", new Date(), metaObject);
        this.setFieldValByName("siteModifyTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("adminModifyTime", new Date(), metaObject);
        this.setFieldValByName("supplierModifyTime", new Date(), metaObject);
        this.setFieldValByName("pileModifyTime", new Date(), metaObject);
        this.setFieldValByName("siteModifyTime", new Date(), metaObject);
    }
}
